<template>
    <div class="tab-box">
        <div :class="{'tab-item': true,active: indexAct == item.index}" v-for="(item,index) in menuStore.tabs"
            :key="index" @click="goTab(item.index)">
            <div class="name">{{item.name}}</div>
            <el-icon class="icon">
                <Close />
            </el-icon>
        </div>
    </div>
</template>
<script setup>
import { computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useMenuStore } from "@/pinia/menu"

const menuStore = useMenuStore()

const router = useRouter()
const route = useRoute()

let indexAct = computed(() => {
    let path = route.path.split('/')
    return `/${path[1]}/${path[2]}`
})

// tab跳转
const goTab = (index) => {
    router.push(index)
}
</script>
<style lang="scss">
.tab-box {
    height: 30px;
    padding-right: 15px;
    box-sizing: border-box;
    flex-grow: 1;
    @include flex();

    .tab-item {
        width: 90px;
        height: 30px;
        border-top: 2px solid #fff;
        color: #7f8180;
        font-size: 12px;
        box-sizing: border-box;
        @include flex(row, center, center);
        cursor: pointer;

        .name {
            width: 60px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .icon {
            color: #a7a7a7;
            margin-left: 5px;
        }
    }

    .tab-item.active {
        border-top: 2px solid #202221;
        color: #252726;
        background-color: #f5f5f5;
    }
}
</style>
  